package com.dhcc.sdc.base.controller;


import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;



import com.dhcc.sdc.base.entity.SdcQcCdssLinkEntity;
import com.dhcc.sdc.base.service.ISdcQcCdssLinkService;


/**
 * 质控项目和CDSS诊疗方案关联表
 * 
 * @ClassName: SdcQcCdssLinkController
 * @Description: TODO
 * @author sunyingjie
 * @date 2022-12-02 13:52:59
 */
@Controller
@RequestMapping("${sys.backendPath}/sdc/sdcqccdsslink")
public class SdcQcCdssLinkController extends BaseController {

	private String PREFIX = "/backend/base/sdcqccdsslink/";

	@Autowired
	private ISdcQcCdssLinkService sdcQcCdssLinkService;
	

    /**
     * 跳转到质控项目和CDSS诊疗方案关联表列表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "sdcqccdsslink.html";
    }
	
    /**
     * 跳转到新增质控项目和CDSS诊疗方案关联表
     */
    @RequestMapping("/to_add")
    public String toAdd() {
        return PREFIX + "sdcqccdsslink_add.html";
    }
	
	/**
     * 跳转到修改质控项目和CDSS诊疗方案关联表
     */
    @RequestMapping("/to_update/{sdcQcCdssLinkId}")
    public String toUpdate(@PathVariable Integer sdcQcCdssLinkId, Model model) {
        SdcQcCdssLinkEntity sdcQcCdssLink = this.sdcQcCdssLinkService.selectById(sdcQcCdssLinkId);
        model.addAttribute("sdcQcCdssLink",sdcQcCdssLink);
        return PREFIX + "sdcqccdsslink_edit.html";
    }

    /**
     * 获取质控项目和CDSS诊疗方案关联表列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam Map<String, Object> params) {
		Page<SdcQcCdssLinkEntity> page = new PageFactory<SdcQcCdssLinkEntity>().defaultPage();
        List<SdcQcCdssLinkEntity> result = this.sdcQcCdssLinkService.page(page,params);
        page.setRecords((List<SdcQcCdssLinkEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增质控项目和CDSS诊疗方案关联表
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(SdcQcCdssLinkEntity sdcQcCdssLink) {
        if (CommonUtil.isOneEmpty(sdcQcCdssLink)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        this.sdcQcCdssLinkService.insert(sdcQcCdssLink);
        return R.ok();
    }

    /**
     * 删除质控项目和CDSS诊疗方案关联表
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer sdcQcCdssLinkId) {
	
        this.sdcQcCdssLinkService.deleteById(sdcQcCdssLinkId);

        return R.ok();
    }

    /**
     * 修改质控项目和CDSS诊疗方案关联表
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(SdcQcCdssLinkEntity sdcQcCdssLink) {
        if (CommonUtil.isOneEmpty(sdcQcCdssLink)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        this.sdcQcCdssLinkService.updateById(sdcQcCdssLink);
        return R.ok();
    }


    /**
     * 根据cdss诊疗方案查询
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/selectByNodeId")
    @ResponseBody
    public Object selectByNodeId(@RequestParam String nodeId) {
        return sdcQcCdssLinkService.selectByNodeId(nodeId);
    }
	
}
